import {defineStore} from 'pinia'
import {reqC1,reqC2,reqC3} from '@/api/product/attr/index'
import type {CategoryState} from '@/stores/interface/index'
import  type {CategoryResponeDate} from '@/api/product/attr/types/index'

 const UseCategoryStore = defineStore('Category',{

    // 存放数据
    state: (): CategoryState => {
        return {
            c1_arr: [],//一级分类的数组
            c1Id:"",    //一级分类的id
            c2_arr: [],//二级分类的数组
            c2Id:"",    //二级分类的id
            c3_arr: [],//三级分类的数组
            c3Id:"",    //三级分类的id
        }
    },

    // 业务逻辑
    actions:{
        async getc1(){
            // 发请求获取一级分类
          let res:CategoryResponeDate =  await reqC1()
            // 数据回来二次赋值
          this.c1_arr = res
        //   console.log(res)
        },
        // 获取二级分类
        async getc2(){
           let res =  await reqC2(this.c1Id as number)
           this.c2_arr = res
        //    console.log(res)
        },
        // 获取三级分类
       async getc3(){
         let reslut  =  await reqC3(this.c2Id as number )
         this.c3_arr = reslut
        //  console.log(reslut)
        }
    },


    // 修改数据
    getters:{

    }

})

// 导出小仓库
export default UseCategoryStore